#include <stdio.h>
#include <stdlib.h>
#include<unistd.h>

//usage format, see docopt. http://docopt.org/
struct cmd_args {
	const char* input_file;
	const char* action;
	const char* output_file;
};

void Usage(char* const* argv)
{
		printf("usage: %s [options] file_path\n", argv[0]);
		printf("options:\n");
		printf("\t-a ACTION\tspecify an action (\"video\", \"audio\", default: \"video\")\n");
		printf("\t-o OUTFILE\tspecify an output file path (default: \"out_file\"))\n");
}

int process_cmd_args(int argc, char* const* argv, struct cmd_args *options)
{
	int ch;		
	while((ch = getopt(argc,argv,"a:o:"))!= -1)
	{
		switch(ch)
		{
			case 'a':
				options->action = optarg;
				break;
			case 'o':
				options->output_file = optarg;
				break;
				/*
			case 'o':
				options->seek_pos = atoi(optarg);
				break;
				*/
			default:
				Usage(argv);
				return -1;	
		}
	}    
	if (optind >= argc) {
				Usage(argv);
				return -1;		
	}
	options->input_file = argv[optind];
	return 0;
}

int main(int argc, char** argv)
{
	struct cmd_args options = {0};
	if (process_cmd_args(argc, argv, &options) < 0)
		return -1;
	fprintf(stdout, "input_file=%s media_type=%s seek_pos=%s\n", options.input_file, options.action, options.output_file);
	return 0;	
}
